package no.group.gowther.service.dto.param;

import no.group.gowther.exception.BusinessException;
import no.group.gowther.exception.ErrorMessage;
import org.springframework.util.CollectionUtils;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

public class FileDeleteDTO {
    private final List<Path> files;

    public FileDeleteDTO(List<Path> file) {
        this.files = file;
        check();
    }

    private void check() {
        if (CollectionUtils.isEmpty(files)) {
            throw BusinessException.createException(ErrorMessage.PARAM_ERROR.getErrorCode(), "删除文件列表为空");
        }
        for (Path file : files) {
            if (!Files.exists(file)) {
                throw BusinessException.createException(ErrorMessage.PARAM_ERROR.getErrorCode(), "文件[%s]不存在".formatted(file));
            }
        }
    }

    public List<Path> getFiles() {
        return files;
    }
}
